//package com.lo.intercepers;
//
//import com.alibaba.fastjson2.JSONObject;
//import com.lo.common.JsonResult;
//import org.springframework.stereotype.Component;
//import org.springframework.web.servlet.HandlerInterceptor;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import javax.servlet.http.HttpSession;
//
////拦截器
//@Component
//public class LoginInterceptor implements HandlerInterceptor {
//    //访问controller方法前   先执行preHandle，所以可以作为是否登录的判断
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        //获取session对象
//        HttpSession session = request.getSession();
//        if (session==null||session.getAttribute("user")==null){
//            //设置中文字符编码和返回值的类型
//           response.setHeader("Content-Type","application/json;charset=utf-8");
//           JsonResult result = new JsonResult(-1,"用户未登录",null);
//           //把result对象转换成json字符串
//            String json = JSONObject.toJSONString(result);
//            //把json字符串输出到前端就可以
//            response.getWriter().write(json);
//            //表示不放行，意味着不能再访问controller对应的方法了
//            return false;
//        }
//        return true;
//
//    }
//}
